<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;

class UserCommission extends Model
{
    use HasFactory;
    use PimpableTrait;

    //可搜索字段
    public $searchable = [
        'id',
        'user_id',
        'account_amount',
        'total_amount',
        'created_at'
    ];
    //更改数据类型
    public $casts = [
        'created_at' => 'date',
    ];

    //全部可批量赋值
    protected $guarded = [];

    //佣金记录所关联的用户的信息
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id')
            ->select('real_name', 'promoter_id', 'brokerage_price', 'balance', 'created_at');
    }

}
